package com.edu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.CommentDTO;
import com.edu.entity.CommonResult;
import com.edu.entity.Page;
import com.edu.entity.UserComents;
import com.edu.entity.Usertags;
import com.edu.service.UserComentsService;
import com.edu.service.UsertagsService;
import com.edu.service.impl.UserComentsServiceImpl;
import com.edu.service.impl.UsertagsServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
@WebServlet("/selectAllUsertags")
public class findAllUsertagsServlet extends HttpServlet{
	UsertagsService uc = new UsertagsServiceImpl();
	CommonResult cr = new CommonResult();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		ObjectMapper om = new ObjectMapper();
		List<Usertags> listUsc = null;
		int rowNum;
		String user_id_String = request.getParameter("userId");
		try {
			int userid = Integer.parseInt(user_id_String);
			listUsc = uc.getUserTags(userid);
			System.out.println(listUsc);
			cr.setCode(200);
			cr.setMessage("success");
		} catch (Exception e) {
			int target_user_id = 0 ;
			int userId = 0;
			cr.setCode(404);
			cr.setMessage("file");
		}

		cr.setData(listUsc);
//		for (int i = 0; i < listUsc.size(); i++) {
//			System.out.println(listUsc.get(i));
//		}
		response.setContentType("application/json;charset=utf-8");
		System.out.println(cr.toJsonString());
		response.getWriter().write(cr.toJsonString());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}
